package net.moonbiter.ebs.callers;

import java.io.File;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.moonbiter.OperationFailureException;
import net.moonbiter.ebs.ServiceCaller;
import net.moonbiter.ebs.protocols.httpparams.HttpParamsInputInterpreter;
import net.moonbiter.ebs.validation.ValidationException;

import org.apache.log4j.Logger;

/**
 * Invocatore di servizi che preleva i parametri logici
 * da parametri Http, esegue l'azione e "logga" i risultati
 * senza consegnarli.
 * 
 * @author federico tomassetti
 */
public class DebugHttpCaller extends ServiceCaller<HttpServletRequest, HttpServletResponse> {
	private final static Logger logger = Logger
			.getLogger(DebugHttpCaller.class);
	private HttpParamsInputInterpreter httpInterp;		

	public DebugHttpCaller(File tmpDirectoryValue, int sizeThresholdValue,
			int maxSize) {
		httpInterp = new HttpParamsInputInterpreter(tmpDirectoryValue,
				sizeThresholdValue,maxSize);
	}

	@Override
	public void deliverError(HttpServletResponse o, Exception exception) {
		logger.debug("Result was an error... : " + exception.getMessage());
	}

	@Override
	protected void deliverResult(HttpServletResponse o, Object result) {
		logger.debug("Result was a success... : "
				+ (result == null ? "<NULL>" : result.toString()));
	}

	@Override
	public Map<String, Object> obtainParams(HttpServletRequest request,
			Map<String, Class<?>> requiredLogicalParams)
			throws OperationFailureException, ValidationException  {		
		return httpInterp.obtainParams(request, requiredLogicalParams);
	}
}
